package me.hgj.jetpackmvvm.util.livedata.unpeeklivedata_7


/**
 * @ClassName UnPeekLiveDataExt
 * @Author yuan_xh
 * @Date 2021/10/19 13:52
 * @Description UnPeekLiveDataExt的扩展使用
 */

class BooleanUnPeekLiveData : UnPeekLiveData<Boolean>() {
    override fun getValue(): Boolean {
        return super.getValue() ?: false
    }
    override fun postValue(value: Boolean) {
        if (this.value != value) {
            super.postValue(value)
        }
    }
}

class IntUnPeekLiveData : UnPeekLiveData<Int>() {
    override fun getValue(): Int {
        return super.getValue() ?: 0
    }
    override fun postValue(value: Int) {
        if (this.value != value) {
            super.postValue(value)
        }
    }
    fun add(num: Int) {
        postValue(value + num)
    }

    fun minus(num: Int) {
        postValue(value - num)
    }

}